package cn.thoughtworks.school.entities;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.hankcs.hanlp.HanLP;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.Objects;

@Entity
@Table(name = "logicQuiz")
@Getter
@Setter
@NoArgsConstructor
public class LogicQuiz {
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;

  @NotNull
  @Min(0)
  @Max(30)
  private int hardCount;

  @NotNull
  @Min(0)
  @Max(30)
  private int normalCount;

  @NotNull
  @Min(0)
  @Max(30)
  private int easyCount;

  @NotNull
  @Min(1)
  @Max(300)
  private int timeBoxInMinutes;
  private String description;
  private int exampleCount;
  private Date createTime;
  private Long quizGroupId;
  private Long makerId;
  private Boolean isAvailable;
  private Long organizationId;

  public LogicQuiz(int easyCount, int exampleCount, int normalCount, int hardCount, int timeBoxInMinutes, String description, Long creatorId, Long organizationId) {
    this.easyCount = easyCount;
    this.exampleCount = exampleCount;
    this.normalCount = normalCount;
    this.hardCount = hardCount;
    this.timeBoxInMinutes = timeBoxInMinutes;
    this.description = description;
    this.createTime = new Date();
    this.makerId = creatorId;
    this.isAvailable = true;
    this.organizationId = organizationId;
  }

  public static LogicQuiz copy(LogicQuiz logicQuiz, Long creatorId, Long organizationId) {
    return new LogicQuiz(logicQuiz.getEasyCount(), logicQuiz.getExampleCount(), logicQuiz.getNormalCount(), logicQuiz.getHardCount(),
      logicQuiz.getTimeBoxInMinutes(), logicQuiz.getDescription(), creatorId, organizationId);
  }

  @JsonProperty("description_zh_TW")
  public String getDescriptionTW() {
    return Objects.isNull(description) ? "" : HanLP.s2tw(description);
  }
}
